'use strict';
// Copyright 2014 Blueant Inc. All Rights Reserved.

/**
 * @fileoverview 好友
 * @author sundbcn@gmail.com (sun debing)
 */

var moment = require('moment');
var modelUtil = require('../util/modelUtil');
var mongoConnector = require('../libs/mongodb/mongoConnector');
/* jshint unused:false */
var friendSchema = require('../schemas/friendSchema');
var Friend = mongoConnector().model('Friend');
var constantUtil = require('../util/constantUtil');

module.exports.getByRoleId = function (role_id, cb) {
    modelUtil.getByRoleId(Friend, role_id, function (err, friend_model) {
        if (!!err) {
            console.error(err);
            return cb(err);
        }

        _dealRequest(friend_model);
        cb(null, friend_model);
    });
};

/**
 * 处理过期好友申请
 * @param  {[type]}   friend_model [description]
 * @param  {Function} cb          [description]
 * @return {[type]}               [description]
 */
var _dealRequest = function (friend_model) {
    friend_model.deleteOutDateRequest();
};

/**
 * 5点刷新
 */
module.exports.onFiveRefresh = function (self, cb) {
    // 重置好友相关信息
    self.refresh();
    cb();
};
